/*******************************************************************************
 * File name: 		main.c
 * Description:
 * Project: 		_framework
 * Target: 			LPC1788
 * Compiler: 		arm-none-eabi-gcc
 * Date: 			Jun 26, 2012
 * Author: 			kuba
 * Based on: 		http://www.freddiechopin.info/
 ******************************************************************************/
/*==============================================================================
 Includes test
==============================================================================*/
# include "init.h"
# include "board.h"
# include "timer.h"
# include "uart.h"
# include "printf.h"
# include "test2.h"
# include "test1.h"
/*==============================================================================
 Globals
==============================================================================*/
static struct io led0, led1, switch0;

/*==============================================================================
 Static function prototypes
==============================================================================*/
static void jtagDelay   (void);
static void timerService (void);
static void switchService (void);

/*==============================================================================
 Main function
==============================================================================*/
int main(void)
{
	jtagDelay();
	systemInit();
	//SystemInit();

	/* peripheral init */
	uart2Init(uartBAUD9600);
	led0 = boardLedInit(gpioPORT0, 25);
	led1 = boardLedInit(gpioPORT0, 23);
	switch0 = boardSwitchInit(gpioPORT2, 10);
	boardSwitchIrqEnable(switch0, irqLOWEST_PRIORITY, switchService);
	timer3Init(SYSTEM_FREQUENCY/10, irqLOWEST_PRIORITY, timerService);
	uprintf("%s\n", "Hey, LPC1788 framework!");


	while (1)
	{
//		if (boardSwitchPressed(switch0))
//		{
//			boardLedToggle(led1);
//		}
	}
}

/*==============================================================================
 Static function definitions
==============================================================================*/
/*------------------------------------------------------------------------------
 function name:   timerService
 description:     led blinking
 parameters:      none
 returned value:  none
------------------------------------------------------------------------------*/
static void timerService (void)
{
	boardLedToggle(led0);
}

/*------------------------------------------------------------------------------
 function name:   switchService
 description:     led blinking
 parameters:      none
 returned value:  none
------------------------------------------------------------------------------*/
static void switchService (void)
{
	boardLedToggle(led1);
}

/*------------------------------------------------------------------------------
 function name:   jtagDelay
 description:     function provides a delay required by jtag
 parameters:      none
 returned value:  none
------------------------------------------------------------------------------*/
static void jtagDelay (void)
{
   volatile uint32 i;
   for (i = 0; i < 1000000; ++i);
}
/******************************************************************************
* END OF FILE
******************************************************************************/
